home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / wait.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-12  |  2.7 KB  |  116 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: wait.c,v 1.4 1996/08/13 13:56:09 digulla Exp $
  4.     $Log: wait.c,v $
  5.     Revision 1.4  1996/08/13 13:56:09  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:21  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include <exec/execbase.h>
  17. #include <aros/libcall.h>
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <clib/exec_protos.h>
  23.  
  24.     __AROS_LH1(ULONG, Wait,
  25.  
  26. /*  SYNOPSIS */
  27.     __AROS_LHA(ULONG, signalSet, D0),
  28.  
  29. /*  LOCATION */
  30.     struct ExecBase *, SysBase, 53, Exec)
  31.  
  32. /*  FUNCTION
  33.     Wait until some signals are sent to the current task. If any signal
  34.     of the specified set is already set when entering this function it
  35.     returns immediately. Since almost any event in the OS can send a
  36.     signal to your task if you specify it to do so signals are a very
  37.     powerful mechanism.
  38.  
  39.     INPUTS
  40.     signalSet - The set of signals to wait for.
  41.  
  42.     RESULT
  43.     The set of active signals.
  44.  
  45.     NOTES
  46.     Naturally it's not allowed to wait in supervisor mode.
  47.  
  48.     Calling Wait() breaks an active Disable() or Forbid().
  49.  
  50.     EXAMPLE
  51.  
  52.     BUGS
  53.  
  54.     SEE ALSO
  55.     Signal(), SetSignal(), AllocSignal(), FreeSignal()
  56.  
  57.     INTERNALS
  58.  
  59.     HISTORY
  60.  
  61. ******************************************************************************/
  62. {
  63.     __AROS_FUNC_INIT
  64.  
  65.     ULONG rcvd;
  66.     struct Task *me;
  67.  
  68.     /* Get pointer to current task - I'll need it very often */
  69.     me=SysBase->ThisTask;
  70.  
  71.     /* Protect the task lists against access by other tasks. */
  72.     Disable();
  73.  
  74.     /* If at least one of the signals is already set do not wait. */
  75.     while(!(me->tc_SigRecvd&signalSet))
  76.     {
  77.     /* Set the wait signal mask */
  78.     me->tc_SigWait=signalSet;
  79.  
  80.     /*
  81.         Clear TDNestCnt (because Switch() will not care about it),
  82.         but memorize it first. IDNestCnt is handled by Switch().
  83.         This could as well be stored in a local variable which makes
  84.         the tc_TDNestCnt field somehow redundant.
  85.     */
  86.     me->tc_TDNestCnt=SysBase->TDNestCnt;
  87.     SysBase->TDNestCnt=-1;
  88.  
  89.     /* Move current task to the waiting list. */
  90.     me->tc_State=TS_WAIT;
  91.     Enqueue(&SysBase->TaskWait,&me->tc_Node);
  92.  
  93.     /* And switch to the next ready task. */
  94.     Switch();
  95.     /*
  96.         OK. Somebody awakened me. This means that either the
  97.         signals are there or it's just a finished task exception.
  98.         Test again to be sure (see above).
  99.     */
  100.  
  101.     /* Restore TDNestCnt. */
  102.     SysBase->TDNestCnt=me->tc_TDNestCnt;
  103.     }
  104.     /* Get active signals. */
  105.     rcvd=me->tc_SigRecvd&signalSet;
  106.  
  107.     /* And clear them. */
  108.     me->tc_SigRecvd&=~signalSet;
  109.  
  110.     /* All done. */
  111.     Enable();
  112.     return rcvd;
  113.     __AROS_FUNC_EXIT
  114. }
  115.  
  116.